package com.lagou.service;

import com.lagou.dao.AccountDao;
import com.lagou.pojo.Account;

/**
 * @author tengfei wang
 * @version 1.0
 * @date Created in 2020/8/31
 */
public class AccountServiceImpl implements AccountService {

    private AccountDao accountDao;

    public void setAccountDao(AccountDao accountDao) {
        this.accountDao = accountDao;
    }

    @Override
    public void transferMoney(String transferFrom, String transferTo, Integer money) {
        Account fromAccount = accountDao.getAccountByCartId(transferFrom);
        Account toAccount = accountDao.getAccountByCartId(transferTo);
        fromAccount.setMoney(fromAccount.getMoney() - money);
        accountDao.updateAccount(fromAccount);
//        int a = 1 / 0;
        toAccount.setMoney(toAccount.getMoney() + money);
        accountDao.updateAccount(toAccount);
    }
}
